New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[common] Add Canonical Serialization Spec #622
Conversation
5aaf596
to
25cb24c
Compare
Please see how the markdown looks here: https://github.com/davidiw/libra/tree/serialization/common/canonical_serialization |
e4b5264
to
d6d482b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments on #606 (review) which actually apply here.
b124642
to
93f7b0b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. Just a couple minor comments. I'd like another set of eyes on it since it's such a large diff though. Would also like Rain/Brandon to look at the macro usage. But overall, I accept
@bmwill, @sunshowers, @metajack I added you as reviewers for my usage of rust macros. Feedback is welcome :). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left a few comments, how much investment in macros you're willing to go for would help fine-tune their relevance.
544fa6e
to
8e2be1d
Compare
d511a46
to
6da3ae0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to keep the macros to the impl rather than to the trait.
macro_rules! impl_canonical_serializer { | ||
($(($function:ident, $type:ty),)+ $(tuple: ($tuple_function:ident, $($tuple_type:ident)+),)+) => ( | ||
/// Trait for serializers that implement LCS | ||
pub trait CanonicalSerializer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as for the macro on pub trait CanonicalDeSerializer
.
Same as title. This defines the spec and gives concrete examples (also implemented in Rust) for RawTransaction and its contents.
Given the importance of canonical serialization within the code base, we are restructuring it to make it to simplify access and understanding. This diff moves each major component into its own separate module (file) and re-exports so as to not break any dependencies. In addition, major types are now fully exposed and implemented, namely signed integers.
Macros reduce the duplicate code. Some challenges arise though: - macros cannot exist within a trait or an impl therefore the macro has to wrap around it so we avoid macros for traits - macros do not support concatenation of inputs, so the entire function name must be specified - macros involving indexes of tuples are just plain complicated and probably less readable for our purposes - tuple of size 1 is colliding with all types -- needs more investigation
Proptest allows for broader testing than fixed sets of test vectors. This diff migrates to proptest and also covers all of the types within LCS which did not have coverage before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos on the excellent, rigorous work on a relatively ungrateful task! Thanks @davidiw
Same as title. This defines the spec and gives concrete examples for
RawTransaction and its contents.
Motivation
Inform those that write clients how to implement the specification for their own domain.
Test Plan
Contains examples and those examples are embedded within new unit tests.
Related PRs
#606